function newStudentselectcourse() {
	greyLayer.open();
	win_selectcourse.window('open');
}
function delStudentselectcourse() {
	// 删除前询问
	$.messager.confirm("用户确认", "确认要取消该课程？", function(r) {
		if (r) {
			var row = selectedcoursegrid.datagrid('getSelected');
			var studentrow = grid_selectstudent.datagrid('getSelected');
			if (row) {
				var url = '/pxglxt/studentselectcourse/destroy?course_id=' + row.id+"&stu_id="+studentrow.id;
				$.post(url, callback);
				// 回调函数
			function callback(data) {
				eval('data=' + data);
				if (data.success) {
					selectedcoursegrid.datagrid('reload');
				} else {
					sys_alert('错误提示', data.msg, 'error');
				}
			}
		} else {
			sys_alert('错误提示', '选择一项记录', 'error');
		}

	}
}	);

}
function closeWindow() {
	win_selectcourse.window('close');
	greyLayer.close();
}
// 查询返回满足条件的学员
function returnstudentforchoose() {
	var stuname, stusex, stusfzh, stumobile, sturegisttime, stutype;
	// 根据用户查询条件返回查询结果
	stuname = $('#stu_name').attr('value');
	stusex = $('#stu_sex').combobox('getValue');
	stusfzh = $('#stu_sfzh').attr('value');
	stumobile = $('#stu_mobile').attr('value');
	sturegisttime = $('#stu_regist_time').attr('value');
	stutype = $('#stu_type').combobox('getValue');
	var sqlwhere = '';
	sqlwhere = 'stu_name=' + stuname + "&stu_sex=" + stusex + "&stu_sfzh="
			+ stusfzh + "&stu_mobile=" + stumobile + "&stu_regist_time="
			+ sturegisttime + "&stu_type=" + stutype;
	// 解决中文从js传入java中乱码的问题
	var url = encodeURI(encodeURI('/pxglxt/studentselectcourse/searchStudents?' + sqlwhere));
	grid_selectstudent = $('#tablestudent')
			.datagrid(
					{
						url : url,
						height : 340,
						pagination : true,
						singleSelect : true,
						fit : true,// 表格自动填充
						loadMsg : '加油处理中... ...',// 加载信息
						rownumbers : true,
						onDblClickRow : function(rowIndex, rowData) {
							// 列出该用户所选的课程
							if (rowData) {
								selectedcoursegrid = $('#studentselectcourse')
										.datagrid(
												{
													url : '/pxglxt/studentselectcourse/getSelectedCourses?stu_id=' + rowData.id,
													pagination : true,
													singleSelect : true,
													fit : true,// 表格自动填充
													loadMsg : '加油处理中... ...',// 加载信息
													toolbar : [
															{
																text : '添加新课程',
																iconCls : 'icon-add',
																enable : true,// 按钮激活
																handler : 'newStudentselectcourse'
															},
															'-',
															{
																text : '取消课程',
																iconCls : 'icon-remove',
																enable : true,// 按钮激活
																handler : 'delStudentselectcourse'
															} ]
												});
								var scpagetool = $('#studentselectcourse').datagrid('getPager');
								scpagetool.pagination({				
									beforePageText:'第',
									afterPageText:'页，共{pages}页',
									displayMsg:'显示从 {from} 到  {to} , 总记录 {total} '});

								// 回填查询
								$('#stu_name').attr('value', rowData.stu_name);
								$('#stu_sex').combobox('setValue',
										rowData.stu_sex);
								$('#stu_sfzh').attr('value', rowData.stu_sfzh);
								$('#stu_mobile').attr('value',
										rowData.stu_mobile);
								$('#stu_regist_time').attr('value',
										rowData.stu_regist_time);
								$('#stu_type').combobox('setValue',
										rowData.stu_type);
							}
							// 关闭窗口和遮罩层
							win_selectstudent.window('close');
							greyLayer.close();
						}
					});
	var stupagetool = $('#tablestudent').datagrid('getPager');
	stupagetool.pagination({				
		beforePageText:'第',
		afterPageText:'页，共{pages}页',
		displayMsg:'显示从 {from} 到  {to} , 总记录 {total} '});
	// 查询，返回满足条件的学生
	win_selectstudent = $('#winstudent').window( {
		collapsible : false,
		minimizable : false,
		maximizable : false,
		closable : true,
		onClose : function() {
			greyLayer.close();
		},
		closed : true
	});
	//
	greyLayer.open();
	win_selectstudent.window('open');
	win_selectstudent.window('refresh');
	//

}
function reloadSearch() {
	$('#stu_name').attr('value', '');
	$('#stu_sex').combobox('setValue', '');
	$('#stu_sfzh').attr('value', '');
	$('#stu_mobile').attr('value', '');
	$('#stu_regist_time').attr('value', '');
	$('#stu_type').combobox('setValue', '');
}
function selectCourse() {
	// 选择的学员信息
	var studentinfo;
	// 选择的课程信息
	var courseinfo = grid_selectcourse.datagrid('getSelected');
	if (courseinfo) {
		studentinfo = grid_selectstudent.datagrid('getSelected');
		// alert(studentinfo.stu_name + "--" + courseinfo.course_name);
		// 学员选课
		var url = '/pxglxt/studentselectcourse/save?stu_id=' + studentinfo.id
				+ '&course_id=' + courseinfo.id;
		$.post(url, callback);
		// 回调函数
		function callback(data) {
			// 接受从服务器端返回的数据
			eval('data=' + data);
			if (data.success) {
				selectedcoursegrid.datagrid('reload');
				sys_alert('信息', "选课成功,课程将于" + courseinfo.course_begin
						+ "开课,请告知学员查看课表！", 'info');
			} else {
				sys_alert('错误提示', data.msg, 'error');
			}
		}
	} else {
		sys_alert('错误提示', '至少选择一个课程', 'error');
	}
	closeWindow();
}